<template>
  <div class="todoapp">
    <todoHeader @create="createFn"></todoHeader>
    <todoMain :arr="nlist" @del="delFn"></todoMain>
    <todoFooter :arr="nlist" @chuan="fn" @clear="clearFn"></todoFooter>
  </div>
</template>

<script>
import "./styles/base.css";
import "./styles/index.css";
import todoHeader from "./components/todoHeater";
import todoMain from "./components/todoMain";
import todoFooter from "./components/todoFooter";
export default {
  components: {
    todoHeader,
    todoMain,
    todoFooter,
  },
  data() {
    return {
      list: [
        { id: 100, name: "吃饭", isDone: true },
        { id: 201, name: "睡觉", isDone: false },
        { id: 103, name: "打豆豆", isDone: true },
      ],
      getAll: "all",
    };
  },
  methods: {
    createFn(taskName) {
      let id =
        this.list.length == 0 ? 100 : this.list[this.list.length - 1].id + 1;
      this.list.push({
        id: id,
        name: taskName,
        isDone: false,
      });
    },
    delFn(index) {
      this.list.splice(index, 1);
    },
    fn(str) {
      this.getAll = str;
    },
    clearFn() {
      this.list = this.list.filter((obj) => obj.isDone === false);
    },
  },
  computed: {
    nlist() {
      if (this.getAll === "yes") {
        return this.list.filter((obj) => obj.isDone === true);
      } else if (this.getAll === "no") {
        return this.list.filter((obj) => obj.isDone === false);
      } else {
        return this.list;
      }
    },
  },
};
</script>

<style>
</style>